<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台用户添加</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/Public/Admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/font-awesome.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="/Public/Admin/css/style.css" rel="stylesheet">
    <link href="/Public/Admin/js/plugins/layer/skin/default/layer.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/switchery/switchery.css" rel="stylesheet">
    <style>
        .btnsub{border:0;outline:0;width: 100px;height:36px;background-color: #05ad94;color:#fff;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form action="<?php echo U('Group/rule');?>" method="post" id="forma">
        <input type="hidden" name="id" value="<?php echo ($id); ?>">
        <div class="col-sm-13">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                <?php if(is_array($datalist)): foreach($datalist as $key=>$vs): ?><div class="row">
                        <label class="checkbox-inline">
                            <input type="checkbox" name="rule_ids[]" value="<?php echo ($vs['id']); ?>" onclick="checkAll(this)" <?php echo ($rule[0]); ?> style="position: relative; top:14px; left: 3px;" <?php if(in_array($vs['id'],$rule)): ?>checked<?php endif; ?>>
                        <h4 style="margin-top: -3px"><?php echo ($vs['title']); ?></h4></label>
                        <div class="hr-line-dashed" style="margin-top: -3px;margin-bottom:10px;"></div>
                        <?php if(!empty($vs['_child'])): if(is_array($vs['_child'])): foreach($vs['_child'] as $key=>$vso): ?><div class="col-sm-13" style="padding-left: 0px;font-size: 12px;">
                            <table class="table table-striped table-bordered table-hover table-condensed">
                                <tr class="b-group">
                                    <th width="10%"><label><?php echo ($vso['title']); ?>&nbsp;&nbsp;
                                    <input type="checkbox" name="rule_ids[]" value="<?php echo ($vso['id']); ?>" onclick="checkAlls(this)" <?php if(in_array($vso['id'],$rule)): ?>checked<?php endif; ?>>
                                    </label></th>
                                    <?php if(!empty($vso['_child'])): ?><td>

                                            <?php if(is_array($vso['_child'])): foreach($vso['_child'] as $key=>$va): ?><label>&nbsp;&nbsp;<?php echo ($va['title']); ?>&nbsp;&nbsp;<input type="checkbox" name="rule_ids[]" value="<?php echo ($va['id']); ?>" <?php if(in_array($va['id'],$rule)): ?>checked<?php endif; ?>></label><?php endforeach; endif; ?>

                                        </td><?php endif; ?>
                                </tr>
                            </table>
                        </div><?php endforeach; endif; endif; ?>
                        </div><?php endforeach; endif; ?>
                    <input type="submit" id="submit" name="submit" value="提交" class="btnsub">
                </div>
            </div>
        </div>
    </form>
</div>
<script src="/Public/Admin/js/jquery.min.js"></script>
<script src="/Public/Admin/js/bootstrap.min.js"></script>
<script src="/Public/Admin/js/plugins/layer/layer.js"></script>
<script src="/Public/Admin/js/comment.js"></script>
<script>
    $(function(){
       $('#submit').click(function(){
            var forma = new FormData (document.getElementById('forma'));
            $.ajax({
                url:$('#forma').prop('action'),
                type:'post',
                data:forma,
                dataType:'json',
                cache:false,
                processData:false,
                contentType:false,
                success:function(data){
                    if(data.status < 1){
                        comment.error(data.mess);
                    }else{
                        comment.success(data.mess,"<?php echo U('Group/rule?id='.$id);?>");
                    }
                }
            });
            return false;
       });
    });
    //全选check
    function checkAll(obj){
        $(obj).parents('.row').eq(0).find("input[type='checkbox']").prop('checked',$(obj).prop('checked'));//prop追加属性
    }
    function checkAlls(obj){
        $(obj).parents('.b-group').eq(0).find("input[type='checkbox']").prop('checked',$(obj).prop('checked'));
    }
</script>
</body>
</html>